home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-05-21 | 12.6 KB | 352 lines | [TEXT/ttxt] |
- --<<<-
- --*******************************************************************************
- --* Demo for: HotSpots
- --* Required files: reqFiles/animate.sx
- --* reqFiles/button.sx
- --* reqFiles/rollover.sx
- --* butnshp.sx
- --* rlovrshp.sx
- --* rlovrbut.sx
- --* NM8rlovr.sx
- --* NM8butn.sx
- --* Author: Su Quek - Kaleida Labs, Inc.
- --*-----------------------------------------------------------------------------*
- --* Description: This script demonstrates how to create different types
- --* of hot spots.
- --* When you run "hotspots.sxt", you should see a window
- --* with 5 types of hotspots (penguins):
- --* animated button
- --* animated rollover
- --* rollover button
- --* rollover shape
- --* button
- --* Move the mouse over each penguin and click on the buttons.
- --* Note: Clicking on the buttons does not really do anything
- --* except hilight the penguin in red. If "hotspots.sxt" is
- --* run in the ScriptX authoring environment, "activate" or
- --* "multiactivate" is displayed in the Listener window.
- --*******************************************************************************
-
- module DemoModule
- uses ScriptX
- end
-
- in module DemoModule
-
- --*=============================================================================*
- --* Set up DirReps
- --*=============================================================================*
- global demoDir := theScriptDir
- global mediaDir := spawn theScriptDir "media"
- global reqFilesDir := spawn theScriptDir "reqfiles"
-
- --*=============================================================================*
- --* Load required files
- --*=============================================================================*
- -- Load Animation
- fileIn reqFilesDir name:"animate.sx"
-
- -- Load Button
- fileIn reqFilesDir name:"button.sx"
-
- -- Load Rollover
- fileIn reqFilesDir name:"rollover.sx"
-
- -- Load ButtonShape
- fileIn demoDir name:"butnshp.sx"
-
- -- Load RolloverShape
- fileIn demoDir name:"rlovrshp.sx"
-
- -- Load RolloverButton
- fileIn demoDir name:"rlovrbut.sx"
-
- -- Load RolloverAnimation
- fileIn demoDir name:"nm8rlovr.sx"
-
- -- Load AnimatedButton
- fileIn demoDir name:"nm8butn.sx"
-
-
- --*=============================================================================*
- --* Define Demo
- --*=============================================================================*
- class Demo (Window)
- end
-
- method makeLabel self {class Demo} bbox label ->
- (
- --*=========================================================================*
- --* Create label
- --*=========================================================================*
- local txt := new TextPresenter boundary:bbox target:label
- setDefaultAttr txt @brush whiteBrush
- setDefaultAttr txt @alignment @center
-
- --*=========================================================================*
- --* Add label to the demo window
- --*=========================================================================*
- prepend self txt
-
- return label
- )
-
- --*=============================================================================*
- --* Method name: importBitmap
- --* Class: Demo
- --* Usage: importBitmap self mediaDir bitmapFile
- --* mediaDir - DirRep
- --* bitmapFile - String object
- --*-----------------------------------------------------------------------------*
- --* Description: Imports the given bitmap from the given directory.
- --*=============================================================================*
- method importBitmap self {class Demo} mediaDir bitmapFile ->
- (
- local theStream := getStream mediaDir bitmapFile @readable
- local theColormap := importMedia theImportExportEngine theStream @image @dib @colormap
- local theBMP := importMedia theImportExportEngine theStream @image @dib @bitmap \
- colormap:theColormap container:self.title
- theBMP.invisibleColor := (new RGBColor red:51 green:51 blue:255)
- return theBMP
- )
-
- --*=============================================================================*
- --* Method name: importSeries
- --* Class: Demo
- --* Usage: importSeries self mediaDir
- --* mediaDir - DirRep
- --*-----------------------------------------------------------------------------*
- --* Description: Imports all bitmaps in the given directory.
- --*=============================================================================*
- method importSeries self {class Demo} mediaDir ->
- (
- local series := #()
-
- --*=========================================================================*
- --* Import all files in the 'media' folder
- --*=========================================================================*
- for bitmapFile in (getContents mediaDir) do
- append series (importBitmap self mediaDir bitmapFile)
-
- --*=========================================================================*
- --* Complete the animation loop
- --*=========================================================================*
- for i := ((size series) - 1) to 2 by -1 do
- append series series[i]
-
- return series
- )
-
-
- method makeButtonShape self {class Demo} x y bmp1 bmp2 ->
- (
- --*=========================================================================*
- --* Create the hotspot
- --*=========================================================================*
- object butnShape (ButtonShape)
- releasedBitmap : bmp1
- pressedBitmap : bmp2
- settings
- x : x
- y : y
- activateAction: (authordata self -> print "activate")
- multiactivateAction: (authordata self n -> print "multiactivate")
- end
-
- --*=========================================================================*
- --* Add hotspot to the demo window
- --*=========================================================================*
- prepend self butnShape
- )
-
- method makeRolloverShape self {class Demo} x y bmp1 bmp2 ->
- (
- --*=========================================================================*
- --* Create the hotspot
- --*=========================================================================*
- object rlovrShape (RolloverShape)
- enterBitmap : bmp1
- exitBitmap : bmp2
- settings
- x : x
- y : y
- end
-
- --*=========================================================================*
- --* Add hotspot to the demo window
- --*=========================================================================*
- prepend self rlovrShape
- )
-
-
- method makeRolloverButton self {class Demo} x y bmp1 bmp2 bmp3 ->
- (
- --*=========================================================================*
- --* Create the hotspot
- --*=========================================================================*
- object rlovrButton (RolloverButton)
- enterBitmap : bmp1
- exitBitmap : bmp2 -- NOTE:exitBitmap = releasedBitmap
- releasedBitmap : bmp2
- pressedBitmap : bmp3
- settings
- x : x
- y : y
- activateAction: (authordata self -> print "activate")
- multiactivateAction: (authordata self n -> print "multiactivate")
- end
-
- --*=========================================================================*
- --* Add hotspot to the demo window
- --*=========================================================================*
- prepend self rlovrButton
- )
-
- method makeAnimatedRollover self {class Demo} x y series ->
- (
- --*=========================================================================*
- --* Create the hotspot
- --*=========================================================================*
- object NM8Rollover (RolloverAnimation)
- series : series
- scale : 8
- settings
- x : x
- y : y
- end
-
- --*=========================================================================*
- --* Add hotspot to the demo window
- --*=========================================================================*
- prepend self NM8Rollover
- )
-
- method makeAnimatedButton self {class Demo} x y series bmp1 ->
- (
- --*=========================================================================*
- --* Create the hotspot
- --*=========================================================================*
- object NM8Button (AnimatedButton)
- series : series
- scale : 8
- pressedBitmap : bmp1
- settings
- x : x
- y : y
- activateAction: (authordata self -> print "activate")
- multiactivateAction: (authordata self n -> print "multiactivate")
- end
-
- --*=========================================================================*
- --* Add hotspot to the demo window
- --*=========================================================================*
- prepend self NM8Button
- )
-
- --*=============================================================================*
- --* Method name: init
- --* Class: Demo
- --* Usage: init self
- --*-----------------------------------------------------------------------------*
- --* Description: Creates a 400x200 window.
- --*=============================================================================*
- method init self {class Demo} #rest args ->
- (
- -- Create a 400x200 window
- apply nextMethod self boundary:(new rect x2:400 y2:200) \
- centered:true \
- fill:(new Brush color:(new RGBColor red:51 green:51 blue:255)) \
- name:"Hotspots" args
- return self
- )
-
- --*=============================================================================*
- --* Method name: afterInit
- --* Class: Demo
- --* Usage: afterInit self
- --*-----------------------------------------------------------------------------*
- --* Description: Calls methods to create the different types of hotspots.
- --*=============================================================================*
- method afterInit self {class Demo} #rest args ->
- (
- --*=========================================================================*
- --* Create an actuator controller to control all the buttons in the demo
- --* window.
- --*=========================================================================*
- new ActuatorController space:self wholespace:true
-
- --*=========================================================================*
- --* Import all required bitmaps
- --*=========================================================================*
- local pen3Dir := spawn mediaDir "pen3anim"
- local pen3Series := importSeries self pen3Dir
-
- local pen4Dir := spawn mediaDir "pen4anim"
- local pen4Series := importSeries self pen4Dir
-
- local pen1a := importBitmap self mediaDir "pen1a.bmp"
- local pen1c := importBitmap self mediaDir "pen1c.bmp"
- local pen2a := importBitmap self mediaDir "pen2a.bmp"
- local pen2c := importBitmap self mediaDir "pen2c.bmp"
- local pen3a := importBitmap self mediaDir "pen3a.bmp"
- local pen3b := importBitmap self mediaDir "pen3b.bmp"
- local pen3c := importBitmap self mediaDir "pen3c.bmp"
-
- --*=========================================================================*
- --* Make hotspots
- --*=========================================================================*
- makeButtonShape self 305 87 pen1a pen1c
- makeRolloverShape self 232 90 pen2a pen2c
- makeRolloverButton self 154 71 pen3c pen3a pen3b
- makeAnimatedRollover self 79 80 pen4Series
- makeAnimatedButton self 0 71 pen3Series undefined
-
- --*=========================================================================*
- --* Make labels for hotspots
- --*=========================================================================*
- makeLabel self (new rect x1:3 y1:20 x2:83 y2:70) "Animated Rollover Button"
- makeLabel self (new rect x1:80 y1:25 x2:160 y2:60) "Animated Rollover"
- makeLabel self (new rect x1:160 y1:25 x2:240 y2:60) "Rollover Button"
- makeLabel self (new rect x1:240 y1:28 x2:320 y2:50) "Rollover"
- makeLabel self (new rect x1:320 y1:28 x2:400 y2:50) "Button"
-
- --*=========================================================================*
- --* Display the demo window
- --*=========================================================================*
- show self
-
- return self
- )
-
- --*=============================================================================*
- --* Create a title container
- --*=============================================================================*
- object tc (TitleContainer)
- dir : demoDir
- path : "hotspots.sxt"
- name : "Hotspots"
- end
-
- --*=============================================================================*
- --* Create demo
- --*=============================================================================*
- object win (Demo)
- title:tc
- end
-
- --*=============================================================================*
- --* Undefine global DirReps
- --*=============================================================================*
- demoDir := undefined
- reqFilesDir := undefined
- mediaDir := undefined
-
- --*=============================================================================*
- --* Store module in the title container
- --*=============================================================================*
- append tc (getModule @DemoModule)
- tc.startUpAction := (tc -> load tc[1]
- show win)
- close tc
- -->>>
-